<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script>
        function openWebSocket(){
            var ws = new WebSocket("ws://localhost:8888/websocket")
            ws.onmessage = function(msg){
                console.log(msg);
            }
            var index = 0
            var timer = setInterval(function(){
                ws.send(JSON.stringify(index++))
                if(index===5){
                    clearInterval(timer)
                     
                } 
            },1000)
            ws.onclose = function(event){
                console.log("WebSocket is closed now.");
            }
        }
    </script>
</head>
<body>
    <h1>Hello WebSocket</h1>
    <button onclick="openWebSocket()">发送Socket</button>
</body>
</html>